<!DOCTYPE html>
<html lang="en">
<!--    课程：黑马程序员  《4个小时带你快速入门vue》
        地址：https://www.bilibili.com/video/BV12J411m7MG -->
<!-- P18 ~ P24 -->

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue基础</title>

    <link rel="stylesheet" href="css/index.css">
</head>

<body>
    <!-- Section标签：文档中的节（section、区段）用于分发内容，即分发部分和子部分。 -->
    <section id="todoapp">
        <!-- 输入框 -->
        <header class="header">
            <h1>小黑笔记本</h1>
            <input v-model="inputValue"  @keyup.enter="add" class="new-todo" type="text" autofocus="autofocus" autocomplete="off" placeholder="请输入任务">
        </header>
        <!-- 列表区域 -->
        <section class="main">
            <ul class="todo-list">
                <li class="todo" v-for="(item,index) in list">
                   <div class="view">
                        <span class="index">{{index+1}}.</span>
                        <label >{{item}}</label>
                        <button class="destroy" @click="remove(index)"></button>
                   </div>     
                </li>
            </ul>
        </section>
        <!-- 统计+清空 -->
        <footer class="footer">
              <span v-show="list.length!=0" class="todo-count">
                <strong>{{list.length}}</strong>
                 items left
              </span>  
              <button v-if="list.length!=0" class="clear-completed" @click="clear">
                Clear
              </button>
        </footer>
    </section>
    <!-- 底部 logo -->
    <footer class="info">
        <p>
            <a href="http://www.itheima.com">
                <img src="images\logo.png" alt="">
            </a>
        </p>
    </footer>

    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> -->
    <script src="../js/vuev2.7.14.js"></script>

    <script>
        var app = new Vue({
            // 通过el属性将 vue实例挂载到div元素的内部
            el: '#todoapp', //推荐使用id选择器
            data: {
                list:["写代码","吃饭饭","睡觉觉"],
                inputValue:"好好学习，天天向上"
            }, 
            methods:{
                add:function(){  
                    console.debug("添加笔记："+this.inputValue);
                    this.list.push(this.inputValue)
                },
                remove:function(index){
                    console.debug("删除：下标="+index);
                    this.list.splice(index,1); //删除元素，通过指定下标与删除个数来删除
                }
                ,
                clear:function(){
                    console.debug("清空笔记");
                    this.list=[];
                }
            }
        })
    </script>


</body>


</html>